package cn.js.servlet;

import cn.js.dao.powerbattery.SysPowerbatteryMapper;
import cn.js.pojo.Powerbattery;
import cn.js.utils.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/PowerBatteryUpdateServlet")
public class PowerBatteryUpdateServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");
        int id = Integer.parseInt(request.getParameter("id"));
        String carName = request.getParameter("carName");
        String cityName = request.getParameter("cityName");
        String userName = request.getParameter("userName");
        int pressureValue= Integer.parseInt(request.getParameter("pressureValue"));

       String time = request.getParameter("time");


        Powerbattery battery = new Powerbattery();
        battery.setPressureValue(pressureValue);
        battery.setUserName(userName);
        battery.setCityName(cityName);
        battery.setCarName(carName);
        battery.setTime(time);
        battery.setId(id);


        SqlSession sqlSession = MyBatisUtil.createSqlSession();
       int  row = sqlSession.getMapper(SysPowerbatteryMapper.class).update(battery);

       sqlSession.commit();

        if (row > 0) {
            request.getRequestDispatcher("index.jsp").forward(request, response);
        }
        MyBatisUtil.createSqlSession();
    }
}
